﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace StoreManagement_Application
{
    public partial class AddRate : Form
    {
        public AddRate()
        {
            InitializeComponent();
        }

        #region Clearing the Fields

        public void ClearFields()
        {

            foreach (Control controls in groupBox1.Controls)
            {

                if (controls is TextBox)
                {
                    ((TextBox)controls).Text = string.Empty;

                }
            }
        }
        #endregion



        private void btnsave_Click(object sender, EventArgs e)
        {
            user_rates rate = new user_rates();
            Guid RateiD = System.Guid.NewGuid();

            rate.RateId = RateiD.ToString();
            rate.ProductName = cmbproductname.Text;
            rate.ProductId = cmbproductname.SelectedValue.ToString();
            rate.OriginalRate = Convert.ToString(numoriginalrate.Value);
            rate.StandardRate = Convert.ToString(numstandardrate.Value);
            rate.NormalRate = Convert.ToString(numnormalrate.Value);
            rate.DateModified = DateTime.Now;
            string status= DataAccessLayer.InsertRateDetails(rate);
            MessageBox.Show("Product "+status);
            
          
        }

        private void btnclear_Click(object sender, EventArgs e)
        {
            ClearFields();
        }

        private void AddRate_Load(object sender, EventArgs e)
        {
            #region binding the combox
            DataTable dt = DataAccessLayer.Bind_ProductName_ProductId();
            DataRow row = dt.NewRow();
            row["ProductName"] = "-Select Product Name-";
            row["productid"] = "-Select Product Name-";

            dt.Rows.InsertAt(row, 0);
            cmbproductname.DataSource = dt;
            cmbproductname.SelectedIndex = 0;
            cmbproductname.DisplayMember = "ProductName";
            cmbproductname.ValueMember = "productid";
            cmbproductname.BindingContext = this.BindingContext;
            #endregion



        }

        private void cmbproductname_SelectedIndexChanged(object sender, EventArgs e)
        {
           

            try
            {
                numoriginalrate.Value = Convert.ToDecimal(DataAccessLayer.Return_PurchasedRate(cmbproductname.SelectedValue.ToString()));
            }
            catch (Exception)
            {


            }
        }


    }
}
